package npr.gui;

import processing.core.PFont;

public class TextButton extends GUI{

    private boolean pressed;
    private String pressedText, releasedText;
    private float pressedTextXPos, releasedTextXPos, textYPos;
    private Field field;
    private Button button;


    public TextButton(int xpos, int ypos, int width, int height, String pressedText, String releasedText, boolean pressed){
	this(xpos, ypos, width, height, null, defaultFontSize, pressedText, releasedText, pressed);
    }

    public TextButton(int xpos, int ypos, int width, int height, PFont font, int fontSize, String pressedText, String releasedText, boolean pressed){
        
	super(xpos, ypos, width, height, font, fontSize);
	this.pressedText= pressedText;
	this.releasedText= releasedText;
	this.pressedTextXPos= textXPos(pressedText);
	this.releasedTextXPos= textXPos(releasedText);
	this.textYPos= textYPos();
        this.pressed= pressed;
	field= new Field(xpos, ypos, width, height);
	button= new Button(xpos, ypos, width, height);
    }


    public boolean isPressed(){

	return pressed;
    }

    protected void mousePressed(int x, int y){
	
	if(inside(x, y)){
	    super.mousePressed(x, y);
	    pressed=!pressed;
	}
    }

    public void draw(){

	if(display){        
	    parent.hint(DISABLE_DEPTH_TEST);
	    parent.textFont(font, fontSize);
	    if(pressed){
		field.draw();
		parent.fill(fontColor);
		parent.text(pressedText, xpos+pressedTextXPos, ypos+height-textYPos);
	    }
	    else{
		button.draw();
		parent.fill(fontColor);
		parent.text(releasedText, xpos+releasedTextXPos, ypos+height-textYPos);
	    }
	    parent.hint(ENABLE_DEPTH_TEST);
	}
    }
}